﻿@{
    System.Data.DataTable kpiData = ViewBag.KpiData;
    if (kpiData.Rows.Count > 0)
    {
        <table style="width: 100%; border-left: 1px solid #507cd1; border-right: 1px solid #507cd1;">
            <thead style="position:sticky;top:0;">
                <tr style="background-color:#507cd1; font-size:18px; color: white; font-weight:bold; height:40px;">
                    <td hidden="hidden">IS_UPDATE</td>
                    <td hidden="hidden">KPI_ID</td>
                    <td width="4%"><input id="kpiTcb" type="checkbox" aria-label="kpiTcb" onchange="kpiTcbChange(event)" /></td>
                    <td width="4%">版本號</td>
                    <td width="4%">域</td>
                    <td width="4%">年度</td>
                    <td width="4%">NO</td>
                    <td width="12%">流程</td>
                    <td width="12%">績效指標</td>
                    <td width="6%">上年度<br />KPI指標</td>
                    <td width="6%">本年度<br />KPI指標</td>
                    <td width="4%">單位</td>
                    <td width="5%">趨勢</td>
                    <td width="5%">數值趨勢</td>
                    <td width="15%">公式</td>
                    <td width="5%">衡量頻率</td>
                    <td width="5%">狀態</td>
                    <td width="5%">流程<br />負責人</td>
                    <td hidden="hidden">RNUM</td>
                </tr>
            </thead>
            <tbody>
                @{
                    int colorIndex = 1;
                    string color;
                    foreach (System.Data.DataRow item in kpiData.Rows)
                    {
                        color = colorIndex % 2 == 1 ? "#eff3fb" : "#ffffff";
                        <tr style="background-color:@color; height:50px;">
                            <td hidden="hidden">N</td>
                            <td hidden="hidden">@item["KPI_ID"].ToString()</td>
                            <td><input class="kpiDcb" type="checkbox" aria-label="kpiDcb" onchange="kpiDcbChange(event)" /></td>
                            <td>@item["VERSION_NO"].ToString()</td>
                            <td>@item["SITE"].ToString()</td>
                            <td>@item["KPI_YEAR"].ToString()</td>
                            <td>@item["KPI_NO"].ToString()</td>
                            <td>@item["KPI_DESC"].ToString()</td>
                            <td>@item["KPI_TARGET"].ToString()</td>
                            <td>@item["PRE_KPI_VALUE"].ToString()</td>
                            <td>
                                @{
                                    if (item["IS_LOCK"].ToString() == "Y" || item["RNUM"].ToString() != "1")
                                    {
                                        <input type="text" value="@item["KPI_VALUE"].ToString()" style="width:70px;height:25px;" onchange="updateKpiFlag(event)" disabled="disabled" />
                                    }
                                    else
                                    {
                                        <input type="text" value="@item["KPI_VALUE"].ToString()" style="width:70px;height:25px;" onchange="updateKpiFlag(event)" />
                                    }
                                }
                            </td>
                            <td>@item["UOM_NM"].ToString()</td>
                            <td>@item["VALUE_TREND"].ToString()</td>
                            <td>@item["TREND_DESC"].ToString()</td>
                            <td>@item["KPI_FUNC"].ToString()</td>
                            <td>@item["FREQ_DESC"].ToString()</td>
                            <td>@item["STATUS_E"].ToString()</td>
                            <td>@item["KPI_OWNER"].ToString()</td>
                            <td hidden="hidden">@item["RNUM"].ToString()</td>
                        </tr>
                        colorIndex++;
                    }
                }
            </tbody>
            <tfoot style="position: sticky; bottom: 0;">
                <tr style="background-color:#507cd1; font-size:15px; color: white; height:35px;">
                    <td colspan="16" style="text-align:left;">
                        &#12288;&#12288;&#12288;
                        第:
                        <span id="pagesIndex">@ViewBag.PagesIndex</span>
                        頁/共:
                        <span>@ViewBag.PagesCount</span>
                        頁
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClick('FP')">首頁</a>
                        <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClick('PP')">上一頁</a>
                        <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClick('NP')">下一頁</a>
                        <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClick('LP')">尾頁</a>
                        轉到第
                        <input id="pagesTo" type="number" value="@ViewBag.PagesIndex" style="height:20px;width:40px;color:black;" />
                        頁
                        <a style="cursor:pointer;color:white;" onclick="btnKpiSearchClick('TP')">Go</a>
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;
                        每頁
                        <select id="pagesNum" style="height: 20px; width: 40px; color: black;" onchange="btnKpiSearchClick('FP')">
                            @{
                                int value = 0;
                                for (int i = 1; i <= 5; i++)
                                {
                                    value = i * 10;
                                    if (ViewBag.pagesNum == i * 10)
                                    {
                                        <option value="@value" selected="selected">@value</option>
                                    }
                                    else
                                    {
                                        <option value="@value">@value</option>
                                    }
                                }
                            }
                        </select>
                        筆/共
                        <span>@ViewBag.DataNums</span>
                        筆
                    </td>
                </tr>
            </tfoot>
        </table>
    }
    else
    {
        <h3>未查詢到數據！</h3>
    }
}